package fischl.douyuApi.model;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

public final class Danmu {
  private static final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");

  public String nn;
  public String ctt;
  public int tl;//弹幕在视频中出现时间，单位是毫秒
  public long sts;//弹幕发送时的时间戳，单位是秒

  @Override
  public boolean equals(Object o) {
    if (o instanceof Danmu) {
      return Objects.equals(nn, ((Danmu) o).nn) && Objects.equals(ctt, ((Danmu) o).ctt);
    }
    return false;
  }

  @Override
  public int hashCode() {
    return Objects.hash(nn, ctt);
  }

  @Override
  public String toString() {
    int secTotal = (tl / 1000);
    int sec = secTotal % 60;
    int minTotal = secTotal / 60;
    int min = minTotal % 60;
    int hour = minTotal / 60;
    StringBuilder builder = new StringBuilder("[");
    if (hour < 10) {
      builder.append("0").append(hour);
    } else {
      builder.append(hour);
    }
    builder.append(":");
    if (min < 10) {
      builder.append("0").append(min);
    } else {
      builder.append(min);
    }
    builder.append(":");
    if (sec < 10) {
      builder.append("0").append(sec);
    } else {
      builder.append(sec);
    }
    builder.append("] ");


    Date date = new Date(sts * 1000);

    builder.append("(").append(format.format(date)).append(")");
    builder.append(" ").append(nn).append(": ").append(ctt);

    return builder.toString();
  }
}